﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Brain.Photon
{
    /// <summary>
    /// Properties for doing stuff with Particles
    /// </summary>
    public class ParticleProperties
    {
        /// <summary>
        /// The Blend State to use while rendering the Particles
        /// </summary>
        public BlendState BlendState = BlendState.AlphaBlend;

        /// <summary>
        /// The Texture itself, used to draw the Particles
        /// </summary>
        public Texture2D Texture;

        private string texturePlace;
        /// <summary>
        /// The place the Texture is
        /// </summary>
        public string TexturePlace
        {
            get { return texturePlace; }
            set
            {
                texturePlace = value;
                Texture = Engine.Instance.ContentManager.Load<Texture2D>(value);
            }
        }

        /// <summary>
        /// Time for the Particle to get the default color(from transparent to the Color property)
        /// </summary>
        public float TimeToDefaultColor = .5f;

        /// <summary>
        /// The Maximum time a Particle stays alive, in seconds
        /// </summary>
        public float MaxTime
        {
            get { return maxTime; }
            set 
            {
                maxTime = value;
                differenceFromFadeOutToEnd = MaxTime - StartFadeOutTime;
            }
        }
        private float maxTime = 4;

        /// <summary>
        /// The Time to start fading out
        /// </summary>
        public float StartFadeOutTime
        {
            get { return startFadeOutTime; }
            set
            {
                startFadeOutTime = value;
                differenceFromFadeOutToEnd = MaxTime - StartFadeOutTime;
            }
        }
        private float startFadeOutTime = 3;

        /// <summary>
        /// The Difference from the Fade Out to the End of the Particle. Used by the Renderers
        /// to know when to start fading out
        /// </summary>
        public float DifferenceFromFadeOutToEnd
        {
            get { return MaxTime - StartFadeOutTime; }
        }
        private float differenceFromFadeOutToEnd;

        /// <summary>
        /// The Minimum Size at the Start of the Particle
        /// </summary>
        public float MinStartSize = 1;
        /// <summary>
        /// The Maximum Size at the Start of the Particle
        /// </summary>
        public float MaxStartSize = 1;

        public float GetRandomStartSize()
        {
            return RandomUtil.Next(MinStartSize, MaxStartSize, 100);
        }

        /// <summary>
        /// The Color the Particle have at it's start
        /// </summary>
        public Color StartColor = Color.White;
        /// <summary>
        /// The Color the Particle have at it's end
        /// </summary>
        public Color EndColor = Color.Transparent;

        /// <summary>
        /// The Gravity Force
        /// </summary>
        public Vector3 Gravity = new Vector3(0, 0, 0);

        #region Making

        public Vector3 EndLinearVelocity = new Vector3(0, 0, 0);

        /// <summary>
        /// The area the Particle will Spawn
        /// </summary>
        public SpawnArea SpawnArea;

        /// <summary>
        /// How much a Particle should lose of Velocity e.a. Linear Velocity will be subtracted
        /// by the multiplication of the last velocity by this value by the Engine's GameTime.TotalSeconds
        /// </summary>
        public Vector3 LinearVelocityLoss = new Vector3(0, 0, 0);

        /// <summary>
        /// The Linear Velocity to be applied when no Velocity is defined
        /// </summary>
        public Vector3 StartLinearVelocity = new Vector3(0, 0, 0);

        /// <summary>
        /// The Angular Velocity to be applied when no Velocity is defined
        /// </summary>
        public Vector3 StartAngularVelocity = new Vector3(0, 0, 0);

        /// <summary>
        /// Minimum random value to apply to the Start Linear Velocity
        /// </summary>
        public Vector3 MinRandomStartLinearVelocity = new Vector3(0);

        /// <summary>
        /// Maximum random value to apply to the Start Linear Velocity
        /// </summary>
        public Vector3 MaxRandomStartLinearVelocity = new Vector3(0);

        /// <summary>
        /// Minimum random value to apply to the Start Angular Velocity
        /// </summary>
        public Vector3 MinRandomStartAngularVelocity = new Vector3(0);

        /// <summary>
        /// Maximum random value to apply to the Start Angular Velocity
        /// </summary>
        public Vector3 MaxRandomStartAngularVelocity = new Vector3(0);

        #endregion
    }
}
